var http = require('http')
var url = require('url')
var fs = require('fs')

var html = '<div>用户名:<input/></div>' +
    '<div>密码:<input/></div>' +
    '<div><button>提交</button></div>'


http.createServer(function (req, res) {
    var urlObj = url.parse(req.url, true);
    var query = urlObj.query;


    if (urlObj.pathname == '/check') {
        if (query.username == 'admin' && query.password == '123456') {
            res.writeHead(200, {'Content-Type': 'text/html; charset=utf8'});
            fs.readFile('template/index.html', function (err, data) {
                res.end(data.toString());
            })
        } else {
            res.end('用户名或者密码错误！')
        }
    }
    
    if (urlObj.pathname == '/login') {
        res.writeHead(200, {'Content-Type': 'text/html; charset=utf8'});
        fs.readFile('template/login.html', function (err, data) {
            res.end(data.toString());
        })
    }


}).listen(3000);

console.log('the server is running at port 3000');
